﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PhaseUatt2
{
    public partial class Form1 : Form
    {
        double w = 0.5;
        double fi= 0.5;
        double dfi = 0.5;
        regulatorConditions cond = new regulatorConditions(0.5, 0.5, 10, 0.5, 0.5, 0.25, 1);




        public Form1()
        {
            InitializeComponent();            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Graphics gPictureBoxe = pictureBox1.CreateGraphics();
            Pen bp = new Pen(Color.Black, 1);
            gPictureBoxe.DrawLine(bp, new Point(259, 0), new Point(259, 25));
            gPictureBoxe.DrawLine(bp, new Point(259, 400), new Point(259, 375));
            gPictureBoxe.DrawLine(bp, new Point(0, 200), new Point(25, 200));
            gPictureBoxe.DrawLine(bp, new Point(493, 200), new Point(518, 200));

            double hx = 51.8;
            for (int i = 1; i <= 9; i++)
            {
                gPictureBoxe.DrawLine(bp, new Point((int)(i * hx), 0), new Point((int)(i * hx), 10));
                gPictureBoxe.DrawLine(bp, new Point((int)(i * hx), 400), new Point((int)(i * hx), 390));
            }
            double hy = 40;
            for (int i = 1; i <= 9; i++)
            {
                gPictureBoxe.DrawLine(bp, new Point(0, (int)(i * hy)), new Point(10, (int)(i * hy)));
                gPictureBoxe.DrawLine(bp, new Point(508, (int)(i * hy)), new Point(518, (int)(i * hy)));
            }
            pictureBox1.Invalidate();
        }
        

        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            Text00.Text = "0";
            Text01.Text = "0";
            Text02.Text = "0";
            Text10.Text = "0";
            Text12.Text = "0";
            Text20.Text = "0";
            Text21.Text = "0";
            Text22.Text = "0";
            

            int x_gr = e.X;
            int y_gr = e.Y;

            textBox1.Text = x_gr.ToString();
            textBox2.Text = y_gr.ToString();

            Graphics gPictureBoxe = pictureBox1.CreateGraphics();
            Pen bp = new Pen(Color.Black, 1);
            gPictureBoxe.DrawLine(bp, new Point(259, 0), new Point(259, 25));
            gPictureBoxe.DrawLine(bp, new Point(259, 400), new Point(259, 375));
            gPictureBoxe.DrawLine(bp, new Point(0, 200), new Point(25, 200));
            gPictureBoxe.DrawLine(bp, new Point(493, 200), new Point(518, 200));

            double hx = 51.8;
            for (int i = 1; i <= 9; i++)
            {
                gPictureBoxe.DrawLine(bp, new Point((int)(i * hx), 0), new Point((int)(i * hx), 10));
                gPictureBoxe.DrawLine(bp, new Point((int)(i * hx), 400), new Point((int)(i * hx), 390));
            }
            double hy = 40;
            for (int i = 1; i <= 9; i++)
            {
                gPictureBoxe.DrawLine(bp, new Point(0, (int)(i * hy)), new Point(10, (int)(i * hy)));
                gPictureBoxe.DrawLine(bp, new Point(508, (int)(i * hy)), new Point(518, (int)(i * hy)));
            }


            w = ((double)(e.X - 259))/259.0;
            fi = ((double)(200-e.Y))/200.0;
            dfi = 0.01;
            double h = 0.001;
            Pen Rp = new Pen(Color.Red, 3);
            for (int i = 0; i < 3000; i++)
            {
                gPictureBoxe.DrawLine(Rp, new Point((int)(cond.RungeKutt4uatt(h, w, dfi, fi)[0] * 259 + 259)+1, (int)(-cond.RungeKutt4uatt(h, w, dfi, fi)[2] * 200 + 200)), new Point((int)(cond.RungeKutt4uatt(h, w, dfi, fi)[0] * 259 + 259), (int)(-cond.RungeKutt4uatt(h, w, dfi, fi)[2] * 200 + 200)));
                w = cond.RungeKutt4uatt(h, w,dfi,fi)[0];
                dfi = cond.RungeKutt4uatt(h, w,dfi,fi)[1];
                fi = cond.RungeKutt4uatt(h, w,dfi,fi)[2];
            }

            

            
        }   
        
    }
}
